package com.dream.keigezhushou.Activity.Fragment;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.dream.keigezhushou.Activity.Uiutils.UiUtils;
import com.dream.keigezhushou.Activity.acty.listen.Golde30SecondsMainActivity;
import com.dream.keigezhushou.Activity.acty.listen.HotRecommendActivity;
import com.dream.keigezhushou.Activity.acty.listen.LocalMusicActivity;
import com.dream.keigezhushou.Activity.acty.listen.PersonalActivity;
import com.dream.keigezhushou.Activity.acty.listen.RecentPlayActivity;
import com.dream.keigezhushou.Activity.acty.listen.golden.Golde30MyCollectedActivity;
import com.dream.keigezhushou.Activity.acty.listen.golden.HotMusicWordsActivity;
import com.dream.keigezhushou.Activity.adapter.FirstAdapter;
import com.dream.keigezhushou.Activity.adapter.MyPagerAdapter;
import com.dream.keigezhushou.Activity.view.CircleImageView;
import com.dream.keigezhushou.Activity.view.NestedScrollViewBottom;
import com.dream.keigezhushou.R;
import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.hintview.ColorPointHintView;
import com.jude.rollviewpager.hintview.IconHintView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by kaifa on 2017/2/24.
 */
public class SongFragment extends Fragment implements View.OnClickListener {

    @BindView(R.id.container)
    LinearLayout container;
    @BindView(R.id.ThirtySecondsPicture)
    TextView ThirtySecondsPicture;
    @BindView(R.id.ThirtyPersonPicture)
    TextView ThirtyPersonPicture;
    @BindView(R.id.ThirtyhotPicture)
    TextView ThirtyhotPicture;
    @BindView(R.id.recomend)
    LinearLayout recomend;
    @BindView(R.id.LocalMusic)
    Button LocalMusic;
    @BindView(R.id.Recentplay)
    Button Recentplay;
    @BindView(R.id.MyCollect)
    Button MyCollect;
    @BindView(R.id.radioGroup2)
    LinearLayout radioGroup2;
    @BindView(R.id.rcl_biaoshengbang)
    RecyclerView rclBiaoshengbang;
    @BindView(R.id.ivBBAlbum)
    CircleImageView ivBBAlbum;
    @BindView(R.id.tvBBTitle)
    TextView tvBBTitle;
    @BindView(R.id.tvBBSinger)
    TextView tvBBSinger;
    @BindView(R.id.ib_Next)
    ImageView ibNext;
    @BindView(R.id.ib_Play_pause)
    ImageView ibPlayPause;
    @BindView(R.id.ib_previous)
    ImageView ibPrevious;
    @BindView(R.id.iv_more)
    ImageView ivMore;
    @BindView(R.id.rlBottomBar)
    RelativeLayout rlBottomBar;
    @BindView(R.id.scl01)
    NestedScrollViewBottom scl01;
    @BindView(R.id.convenientBanner)
    RollPagerView convenientBanner;

    private Intent intent;

    private ArrayList<Integer> picture = new ArrayList<Integer>();
    private ArrayList<String> Ms;
    private FirstAdapter firstAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = UiUtils.inflateView(R.layout.laout_song_fragment);
        ButterKnife.bind(this, view);

        /**控件初始化*/
//        setViews();
        /**设置监听*/
        setListeners();
        initMs();
//        rclBiaoshengbang.setLayoutManager(new GridLayoutManager(getBaseContext(),2));
        rclBiaoshengbang.setLayoutManager(new LinearLayoutManager(getContext()));
        firstAdapter = new FirstAdapter(getContext(), Ms);
        rclBiaoshengbang.setFocusable(false);
        rclBiaoshengbang.setAdapter(firstAdapter);
//        rclBiaoshengbang.addItemDecoration(new DividerItemDeoration(this, DividerItemDeoration.VERTICAL_LIST));

        /**
         *   图片的轮播
         *
         */

//        convenientBanner.setHintView(new IconHintView(getActivity(),R.mipmap.a_b,R.mipmap.a_a));
        convenientBanner.setHintView(new ColorPointHintView(getActivity(),Color.BLUE,Color.WHITE));
        convenientBanner.setAdapter(new MyPagerAdapter(convenientBanner));
//        picture.add(R.mipmap.a_001);
//        picture.add(R.mipmap.a_002);
//        picture.add(R.mipmap.a_003);
//
//
//        //开始自动翻页
//        convenientBanner.setPages(new CBViewHolderCreator() {
//            @Override
//            public Object createHolder() {
//                return new LocalImageHolderView();
//            }
//        }, picture)
//                //设置指示器是否可见
//                .setPointViewVisible(true)
//                //设置自动切换（同时设置了切换时间间隔）
//                .startTurning(2000)
//                //设置两个点图片作为翻页指示器，不设置则没有指示器，可以根据自己需求自行配合自己的指示器,不需要圆点指示器可用不设
//                .setPageIndicator(new int[]{R.mipmap.a_a, R.mipmap.a_b})
//                //设置指示器的方向（左、中、右）
//                .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL)
//                //设置点击监听事件
////                .setOnItemClickListener(this)
//                //设置手动影响（设置了该项无法手动切换）
//                .setManualPageable(true);

        //设置翻页的效果，不需要翻页效果可用不设
        //setPageTransformer(Transformer.DefaultTransformer);   // 集成特效之后会有白屏现象，新版已经分离，如果要集成特效的例子可以看Demo的点击响应。
        return view;
    }

    private void initMs() {
        Ms = new ArrayList<String>();
        for (int i = 0; i < 3; i++) {
            Ms.add("" + (char) i);

        }
    }

//    //图片的点击事件
//    @Override
//    public void onItemClick(int position) {
//        Toast.makeText(this, "position:" + position, Toast.LENGTH_SHORT).show();
//    }

//    //为了方便改写，来实现复杂布局的切换
//    private class LocalImageHolderView implements Holder<Integer> {
//        private ImageView imageView;
//
//        @Override
//        public View createView(Context context) {
//            //你可以通过layout文件来创建，不一定是Image，任何控件都可以进行翻页
//            imageView = new ImageView(context);
//            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
//            return imageView;
//        }
//
//        @Override
//        public void UpdateUI(Context context, int position, Integer data) {
//            imageView.setImageResource(data);
//        }
//    }

    /**
     * 轮滚图结束
     */


    private void setListeners() {

        ThirtyhotPicture.setOnClickListener(this);
        ThirtyPersonPicture.setOnClickListener(this);
        ThirtySecondsPicture.setOnClickListener(this);
        LocalMusic.setOnClickListener(this);
        Recentplay.setOnClickListener(this);
        MyCollect.setOnClickListener(this);

        //滑动到底部的监听
        scl01.setScrollBottomListener(new NestedScrollViewBottom.ScrollBottomListener() {
            @Override
            public void scrollBottom() {

                //滑动到了底部
            }
        });
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ThirtySecondsPicture:
                intent = new Intent(getContext(), Golde30SecondsMainActivity.class);
                startActivity(intent);
                break;
            case R.id.ThirtyPersonPicture:
                intent = new Intent(getContext(), PersonalActivity.class);
                startActivity(intent);
                break;
            case R.id.ThirtyhotPicture:
                intent = new Intent(getContext(), HotRecommendActivity.class);
                startActivity(intent);
                break;

            case R.id.LocalMusic:
                intent = new Intent(getContext(), LocalMusicActivity.class);
                startActivity(intent);
                break;
            case R.id.Recentplay:
                intent = new Intent(getContext(), RecentPlayActivity.class);
                startActivity(intent);

                break;
            case R.id.MyCollect:
                intent=new Intent(getContext(),Golde30MyCollectedActivity.class);
                intent.putExtra("state","我的收藏");
                startActivity(intent);
                break;
            case  R.id.rlBottomBar:

                intent =new Intent(getContext(),HotMusicWordsActivity.class);
                startActivity(intent);
                break;

        }

    }

}
